package com.ktgj.customer.domain.Insurance.dxModel;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.ktgj.customer.domain.Insurance.axModel.Insured;
import com.ktgj.common.core.utils.DateUtils;
import com.ktgj.common.core.utils.RSAUtils;
import com.ktgj.common.core.utils.xml.XElement;
import com.ktgj.common.core.utils.xml.XmlUtils;
import com.ktgj.common.core.utils.*;
import com.ktgj.customer.domain.Insurance.axModel.*;
import org.apache.commons.codec.digest.DigestUtils;
import org.aspectj.weaver.ast.Test;
import org.springframework.beans.factory.annotation.Autowired;
import sun.misc.BASE64Encoder;


import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.Key;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import java.security.SecureRandom;
import java.security.spec.InvalidKeySpecException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.logging.Logger;

public class kbdx extends Throwable {

    private Object RSASecurity;

    private void OpenFlightInsurance(List<MemberInsuranceInfo> rbList) throws InvalidKeySpecException, NoSuchAlgorithmException {
        String request = null; //请求参数（密文）
        String errorMg = null; //异常信息
        String strResponse = null; //响应参数(明文)
        DXBizData bizData = new DXBizData(); //请求实体

        DXInsured dxInsured = new DXInsured();
        dxInsured.setBirthday(DateUtils.getNowDate().toString());
        dxInsured.setCertificateCode("231182200010260536");
        dxInsured.setGender(0);
        dxInsured.JSJOrderId = "123456789";
        dxInsured.setMobile("18745654672");
        dxInsured.setName("李博洋");

        DXOrderInfo dxOrderInfo = new DXOrderInfo();
//        dxOrderInfo.setFromTime(DateUtils.getNowDate());
        dxOrderInfo.setGoodsId(1110275);
        dxOrderInfo.getInsureds().add(dxInsured);
        dxOrderInfo.setSkuId(1110544);

        String rsaKey = RSAUtils.publicEncrypt(JSON.toJSONString(dxOrderInfo), RSAUtils.getPublicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCisiHg89yyyB2bN6V3ws6GRm4tJpgfMwuffOX4iV6l8XRTRP1v5BOqIBe5uDrbWRG6JX8A1HpwSixr/cSeG8hsZ++oX8m+XkvwMtr3ivLh1BNat3+8p8QqvyC2bd3vlkUg0RXinGw7vL/NcWXe49PbeT8UNe0B6tUoyrnufMiGkQIDAQAB"));
        DXRequest dxRequest = new DXRequest();
        dxRequest.setBizData(rsaKey);

        String respose =  HttpClientUtil.doPostJson("https://tapi.bz365.com/api/smgw.do",JSON.toJSONString(dxRequest));

    }

    /**
     * 查询保险状态（通过第三方查询）
     * */
    public String SearchInsPolicy() throws InvalidKeySpecException, NoSuchAlgorithmException {

        Logger logger=Logger.getLogger(String.valueOf(Test.class));


        GetPolicyStateRequest dxBizData = new GetPolicyStateRequest();
        dxBizData.setApiName("orderByCardAndGoodsId");
//        dxBizData.setCardId("220106198109220818");
        dxBizData.setCardId("3254354354");
        dxBizData.setGoodsId(String.valueOf(1110275));

        String rsaKey = RSAUtils.publicEncrypt(JSON.toJSONString(dxBizData), RSAUtils.getPublicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCisiHg89yyyB2bN6V3ws6GRm4tJpgfMwuffOX4iV6l8XRTRP1v5BOqIBe5uDrbWRG6JX8A1HpwSixr/cSeG8hsZ++oX8m+XkvwMtr3ivLh1BNat3+8p8QqvyC2bd3vlkUg0RXinGw7vL/NcWXe49PbeT8UNe0B6tUoyrnufMiGkQIDAQAB"));
        DXRequest dxRequest = new DXRequest();
        dxRequest.setBizData(rsaKey);

        String response =  HttpClientUtil.doPostJson("https://tapi.bz365.com/api/smgw.do",JSON.toJSONString(dxRequest));
        GetPolicyStateResponse policyStateResponse = JSON.parseObject(response,GetPolicyStateResponse.class);
        System.out.println(policyStateResponse.message);
        return response;

}

//    @Autowired
//    DxInsuranceUtils dxInsuranceUtils;

    /**
     * 短期交通意外险
     * @return
     * @throws InvalidKeySpecException
     * @throws NoSuchAlgorithmException
     */
    public String DxAccidentApply() throws InvalidKeySpecException, NoSuchAlgorithmException {

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        DXInsured dxInsured = new DXInsured();
        dxInsured.setMobile("18310769919");
        dxInsured.setGender(1);
        dxInsured.setName("李某");
        dxInsured.setBirthday("1981-09-22");
        dxInsured.JSJOrderId="123456789";
        dxInsured.setCertificateType(1);
        dxInsured.setCertificateCode("220106198109220818");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(DateUtils.getNowDate());
        calendar.add(Calendar.DATE,1);
        DXOrderInfo dxOrderInfo = new DXOrderInfo();
//        dxOrderInfo.setFromTime(format.format(calendar.getTime()));
        dxOrderInfo.setGoodsId(1110380);
        dxOrderInfo.setSkuId(1110730);
        dxOrderInfo.timeStamp = DateUtils.getNowDate().getTime();

        List<DXInsured> dxInsureds=new ArrayList<>();
        dxInsureds.add(dxInsured);
        dxOrderInfo.setInsureds(dxInsureds);
        dxOrderInfo.collectionFlag = "Y";

        InsureRequest bizData = new InsureRequest();
        bizData.setOrderInfo(dxOrderInfo);

//        InsureResponse insureResponse = dxInsuranceUtils.openInsurance(bizData);

//        String info  = "{\"apiName\":\"jsjOrder\",\"apiVersion\":\"1.0.1\",\"partnerUserId\":\"1234\",\"osType\":\"ios\",\"orderInfo\":{\"timeStamp\":1630640415384,\"fromTime\":\"2021-09-03T14:40:00\",\"goodsId\":1110380,\"skuId\":1110730,\"insureds\":[{\"JSJOrderId\":\"6f74c0741a1b4c1\",\"name\":\"xxxx\",\"certificateType\":1,\"certificateCode\":\"xxxxx0\",\"gender\":1,\"birthday\":\"1982-08-27\",\"mobile\":\"15835xxxx\"}],\"collectionFlag\":\"Y\"}}";

//        String rsaKey = RSAUtils.publicEncrypt(info, RSAUtils.getPublicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCisiHg89yyyB2bN6V3ws6GRm4tJpgfMwuffOX4iV6l8XRTRP1v5BOqIBe5uDrbWRG6JX8A1HpwSixr/cSeG8hsZ++oX8m+XkvwMtr3ivLh1BNat3+8p8QqvyC2bd3vlkUg0RXinGw7vL/NcWXe49PbeT8UNe0B6tUoyrnufMiGkQIDAQAB"));
//        String rsaKey = RSAUtils.publicEncrypt(JSON.toJSONString(bizData,SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.WriteDateUseDateFormat), RSAUtils.getPublicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCisiHg89yyyB2bN6V3ws6GRm4tJpgfMwuffOX4iV6l8XRTRP1v5BOqIBe5uDrbWRG6JX8A1HpwSixr/cSeG8hsZ++oX8m+XkvwMtr3ivLh1BNat3+8p8QqvyC2bd3vlkUg0RXinGw7vL/NcWXe49PbeT8UNe0B6tUoyrnufMiGkQIDAQAB"));
//
//        DXRequest dxRequest = new DXRequest();
//        dxRequest.setBizData(rsaKey);
//
//        String respose =  HttpClientUtil.doPostJson("https://tapi.bz365.com/api/smgw.do",JSON.toJSONString(dxRequest));
//        InsureResponse insureResponse = JSON.parseObject(respose,InsureResponse.class);

//        String data ="{\"partnerId\":\"jinseshiji\",\"apiVersion\":\"1.0.1\",\"bizData\":\"F+C9g96wmf3TSrcYJqU7acTeqec/yepOEK0U2Z1V7rA0ekfrlHt0wDbJcsTUEQ1pz+KWxS6xs7ss1YOK8ycYl8pHLChfuf0bQkO4QEf42JYOXw/n+4jl6mcvKBtHuKh32YRqKb/L0ecVd8feAXm5s85i5669VNU9/vbV7ik6JYMjaSuFFCp5CAYIMrr13UHfcWcpp6lvfL17E8y4ghY9iagFyXpODNxVlFHhFRKqpaMc7n1tXW2iiNVmXYE7XMOWWduhq33hsFn7u5VcDGBNawyx+p6H1keQKLlOdisyjuKSvdbWL37oV4HQaYwt5zgIcp+aRbAhqaZCc8p4ESKWC0505Sqn6N5kXh3hQlpviot3MQ5Xz0qFrNb21e3qZwMQexDMvenBC2z1SrhTa6VnXsvWD6+BG7FVXDsVRHYanOd44DP24wpmUFdBPLmMKB6w0Pdt8tq59VQa0zdRpXW7ilPS3fvawqnNUYlTs59SNrBia+FL5v38PXIg4NH5yF6VD00qpjGKY875fKXf5cxI98tCMsR06Tr+O45Pq2j5D2jJY6AfWpifU2kIJWRj/B83Q1LTXgQImkwuNa6kjRJD49nPIPdPWvpTPE3A1p+iQ20LMlmlIEVqDvF8TyZei4U4Zu8tA/qVnbderUupmf9NcpYb4iQ6cLF28MVToDGtkEM=\"}";
//        String respose =  HttpClientUtil.doPostJson("https://tapi.bz365.com/api/smgw.do",data);

        return "";
    }

    /**
     * wyj (大象保险)
     金色平台 手动修改信息点击“开保”
     * @return 返回请求结果
     * @throws InvalidKeySpecException
     * @throws NoSuchAlgorithmException
     */
    public String ManualOpenInsurance () throws InvalidKeySpecException, NoSuchAlgorithmException {

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        //订单信息
        DXOrderInfo dxOrderInfo = new DXOrderInfo();
//        dxOrderInfo.setFromTime(format.format(DateUtils.getNowDate()));
        dxOrderInfo.setGoodsId(1110275);
        dxOrderInfo.setSkuId(1110544);


        DXInsured dxInsured = new DXInsured();
        dxInsured.setBirthday("2000-10-26");
        dxInsured.setCertificateCode("231182200010260536");
        dxInsured.setGender(1);
        dxInsured.setCertificateType(1);
        dxInsured.JSJOrderId = "123456987";
        dxInsured.setMobile("17610641000");
        dxInsured.setName("李博洋");

        List<DXInsured> dx = new ArrayList<>();
        dx.add(dxInsured);

        dxOrderInfo.setInsureds(dx);

        InsureRequest bizData = new InsureRequest();
        bizData.orderInfo = dxOrderInfo;

        //深度加密
        String rsaKey = RSAUtils.publicEncrypt(JSON.toJSONString(bizData), RSAUtils.getPublicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCisiHg89yyyB2bN6V3ws6GRm4tJpgfMwuffOX4iV6l8XRTRP1v5BOqIBe5uDrbWRG6JX8A1HpwSixr/cSeG8hsZ++oX8m+XkvwMtr3ivLh1BNat3+8p8QqvyC2bd3vlkUg0RXinGw7vL/NcWXe49PbeT8UNe0B6tUoyrnufMiGkQIDAQAB"));

        //发送请求
        DXRequest dxRequest = new DXRequest();
        dxRequest.setBizData(rsaKey);

        String respose = HttpClientUtil.doPostJson("https://tapi.bz365.com/api/smgw.do", JSON.toJSONString(dxRequest));

        return respose;
    }

    /**
     * 大象短期交通意外险退保
     * @return
     * @throws InvalidKeySpecException
     * @throws NoSuchAlgorithmException
     */
    public String DxSurrender() throws InvalidKeySpecException, NoSuchAlgorithmException {
        Date startTime = new Date();
        String response = null;
        RefundInfo refundInfo = new RefundInfo();
        refundInfo.setTimeStamp(DateUtils.getTime().toString());
        refundInfo.setCertificateCode("220106198109220818");
        refundInfo.setCertificateType(1);
        refundInfo.setMergeOrderId("210911173806095702");
        refundInfo.setPolicyNo("ABEJ600E4021PAAAAA2N");
        refundInfo.setPrice(120);
        refundInfo.settName("李某");

        RefundRequset refundRequset = new RefundRequset();
        refundRequset.setRefundInfo(refundInfo);

        String rsaKey = RSAUtils.publicEncrypt(JSON.toJSONString(refundRequset, SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.WriteDateUseDateFormat), RSAUtils.getPublicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCisiHg89yyyB2bN6V3ws6GRm4tJpgfMwuffOX4iV6l8XRTRP1v5BOqIBe5uDrbWRG6JX8A1HpwSixr/cSeG8hsZ++oX8m+XkvwMtr3ivLh1BNat3+8p8QqvyC2bd3vlkUg0RXinGw7vL/NcWXe49PbeT8UNe0B6tUoyrnufMiGkQIDAQAB"));
        DXRequest dxRequest = new DXRequest();
        dxRequest.setBizData(rsaKey);

        String resposeString = HttpClientUtil.doPostJson("https://tapi.bz365.com/api/smgw.do", JSON.toJSONString(dxRequest));
        RefundResponse refundResponses = JSON.parseObject(resposeString, RefundResponse.class);
        return refundResponses.message;
    }

    /**
     * wyj 大象保险理赔（誉好）
     * @return 请求结果
     * @throws IOException
     */
    public String YuHaoClaim() throws IOException {

        int result=132453;  //理赔订单id
        String YuhaoDesKey = "yhcgfln2";
        String YuhaoSignKey= "flygc826nu";
        String YuhaoVersion = "v1.0";
        String YuhaoUserName ="yuhao_goldencentury";
        String YuhaoCmd="validateClaimInfoGoldenCentury";


        YuHaoCommonRequest request = new YuHaoCommonRequest();
        request.setUserName(YuhaoUserName);
        request.setCmd(YuhaoCmd);
        request.setVersion(YuhaoVersion);

        //des加密
        StringBuilder bu = new StringBuilder();
        bu.append(JSON.toJSONString(result)); //delayClaimOrderId
        bu.append(YuhaoDesKey); //desKey
        String encryptString = DesUtil.getEncryptString(bu.toString());
        //data值
        request.setData(encryptString);

        //md5加密
        StringBuilder builder=new StringBuilder();
        builder.append(YuhaoCmd);
        builder.append(request.getData());
        builder.append(YuhaoVersion);
        builder.append(YuhaoUserName);
        builder.append(YuhaoSignKey);
        String encrypt = MyMD5Util.encrypt(builder.toString());
        //sign值
        request.setSign(encrypt);

        //获取接口名称
        RefundRequset refundRequset = new RefundRequset();
        refundRequset.setCommonRequest(request);


        //发送请求
        //String respose = HttpClientUtil.doPostJson("http://123.56.2.25:8088/yh_clientweb/access20/receiveStream.jhtml", JSON.toJSONString(refundRequset));

        Map<String, Object> map = new HashMap<>();
        map.put("test", refundRequset);
        URL url = new URL("http://123.56.2.25:8088/yh_clientweb/access20/receiveStream.jhtml");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.addRequestProperty("Accept", "application/json");
        conn.addRequestProperty("Content-Type", "application/json;charset=utf-8");
        conn.setRequestMethod("POST");

        conn.setUseCaches(false);
        conn.setInstanceFollowRedirects(true);
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.connect();

        OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());
        out.write(JSON.toJSONString(map));
        out.flush();

        InputStream is = conn.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
        StringBuffer sbf = new StringBuffer();
        String temp = null;
        // 循环遍历一行一行读取数据
        while ((temp = br.readLine()) != null) {
            sbf.append(temp);
        }

        System.out.println(sbf.toString());
        br.close();

        return temp;
    }

    public String testAXOpen() {
        FlightTgt flight = new FlightTgt();
        flight.seq = "1";//序号
        flight.flightNum = "MF8059";//航班号
        flight.departrueCity = "JJN";//起飞城市
        flight.arriveCity = "SHE";//到达城市
        flight.takeOffTime = "2022-01-24 12:49:31";//航班计划起飞时间
        flight.airways = "厦航";//航空公司
        flight.arriveTime = "2022-01-24 17:55:00";//航班计划到达时间
        flight.ticketNum = "7312437773652";//票号
        flight.berth = "R";//舱位
        flight.coupon = "1";//中转航程号
        ChangeBackTgt changeBack = new ChangeBackTgt();
        changeBack.beforeChange = "1000";//航前改期费（起飞时限前改期费）
        changeBack.beforeTimeChange = "1000";//航前时限内改期费（起飞时限内改期费）
        changeBack.afterChange = "1000";//航后改期费（起飞后改期费）
        changeBack.changeTime = "0";//改期时间点 2代表起飞前2小时之前,0代表起飞前0小时之前(改期时限)
        changeBack.beforeBack = "1000";//航前退票费（起飞时限前退票费）
        changeBack.beforeTimeBack = "1000";//航前退票费（起飞时限内退票费）
        changeBack.afterBack = "1000";//航后退票费（起飞后退票费）
        changeBack.backTime = "0";//退票时间点 2代表起飞前2小时之前,0代表起飞前0小时之前（退票时限）
        Holder h = new Holder();
        h.name = "李博洋";//姓名
        h.email = "";//邮箱地址
        h.cardType = "120001";//证件类型
        h.cardNo = "231182200010260536";//证件号码
        h.birthday = "2000-10-26";//投保人生日
        h.sex = "";//性别
        h.province = "";//省份
        h.city = "";//城市
        h.mobile = "18745654672";//手机电话
        h.address = "";//地址
        h.zipCode = "";//邮编
        h.telArea = "";//固话区号
        h.tel = "";//固话号码
        Insured in = new Insured();
        in.seq = "1";//序号
        in.relationship = "601005";//与投保人关系
        in.name = "李博洋";//姓名
        in.email = "";//邮箱地址
        in.cardType = "120001";//证件类型
        in.cardNo = "231182200010260536";//证件号码
        in.birthday = "2000-10-26";//投保人生日 yyyy-MM-dd
        in.sex = "";//性别  1 男 2 女
        in.province = "";//省份
        in.city = "";//城市
        in.mobile = "";//手机电话
        in.address = "";//地址
        in.zipCode = "";//邮编
        in.isLegal = "1";//是否是法定受益人 如果是法定受益人，则受益人信息不传。[代码值没有提供] 1是0否
        List<Benefited> benefitedList = new ArrayList<>();
        Benefited ben = new Benefited();
        ben.seq = "";//序号
        ben.name = "";//姓名
        ben.email = "";//邮箱地址
        ben.cardType = "";//证件类型
        ben.cardNo = "";//证件号码
        ben.birthday = "";//投保人生日
        ben.sex = "";//性别
        ben.province = "";//省份
        ben.city = "";//城市
        ben.mobile = "";//手机电话
        ben.address = "";//地址
        ben.zipCode = "";//邮编
        ben.position = "";//第几受益人
        benefitedList.add(ben);
        in.benefitedList = benefitedList;//受益人信息（节点）
        List<Order> ord = new ArrayList<>();
        Order or = new Order();
        or.orderId = "JSSJ4089852`6190~16038584{42039a8d-4";//订单号
        or.prodNo = "080026";//险种代码
        or.totalPremium = "30.00";//总保费
        or.prevPremium = "30.00";//折前保费
        or.discountRate = "";//折扣率
        or.actualPremium = "30.00";//实际保费
        or.totalAmount = "";//总保额
        or.appTm = "2022-01-24 12:49:31";//投保日期 yyyy-MM-dd HH:mm:ss
        or.insBeginDate = "2022-01-24 10:49:31";//保险起期 yyyy-MM-dd HH:mm:ss 保险起期传计划起飞时间，
        or.insEndDate = "2022-01-26 12:49:30";//保险止期  yyyy-MM-dd HH:mm:ss 止期:计划起飞时间+2天-1秒
        or.applyNum = "1";//投保份数 本期值为1，下期如果允许输入份数，再变更值。即使多被保人，仍然填写1
        or.seePayment = "1";//是否见费出单 0非见费出单，则请求一次核保，出单；1见费出单；默认 1 ，金色世纪全部是见费出单
        or.insureProvince = "";//承保地区，省
        or.insureCity = "";//承保地区，市
        or.insureCountry = "";//承保地区，区、县
        or.flightTgt = flight;//航班信息 （航延险、机票变更、行李保障 传参）
        or.changeBackTgt = changeBack;//改退信息（机票变更 传值）
       /* or.addressTgt = add;//财产险类 （未使用）
        or.serviceTgt = ser;//责任险类 （未使用）
        or.hotelTgt = ho;//酒店信息*/
        ord.add(or);
        List<Insured> lstInsured = new ArrayList<>();
        lstInsured.add(in);
        ApplyInfo applyInfo = new ApplyInfo();
        applyInfo.holder = h;//投保人信息
        applyInfo.insured = lstInsured;//被保人信息
        ApplyRequestPackage applyRequestPackage = new ApplyRequestPackage();
        RequestHeader header = new RequestHeader();
        header.requestType = "UNDERWRITE";//交易类型
        header.from = "EC16070003";//渠道编号
        header.sendTime = "2022-01-24 12:28:04";//发送时间 yyyy-MM-dd HH:mm:ss
        header.orderId = "JSSJ4089852`6190~16038584{42039a8d-4";//渠道订单号
        header.payNo = "";//支付交易流水号 （非必填）
        header.payType = "";//支付方式（非必填）
        header.payTime = "";//支付时间（非必填）
        header.asyn = "0";//是否异步接口 目前只支持同步，缺省为同步，默认值为：0
        header.isGroup = "0";//是否团单 如果是团单，默认值为：0  是：1，否：0
        header.returnUrl = "";//回调Url  对于异步返回接口(核保和出单)，保险公司回调请求渠道的地址，保险公司需用此地址。（预留字段）
        header.productCode = "TP080113";//产品代码
        header.productName = "安心延误保障计划（航后款）";//产品名称

        applyRequestPackage.header = header;

        ApplyRequest applyRequest = new ApplyRequest();
        applyRequestPackage.request = applyRequest;
        applyRequest.order = ord;
        applyRequest.applyInfo = applyInfo;

        List<ApplyRequestPackage> lstApplyRequest = new ArrayList<>();
        lstApplyRequest.add(applyRequestPackage);

        AXApplyInsuranceRequest axApplyInsurance = new AXApplyInsuranceRequest();
        axApplyInsurance.packages = lstApplyRequest;

        List<AXApplyInsuranceRequest> lstAxRequest = new ArrayList<>();
        lstAxRequest.add(axApplyInsurance);
        AnXinInsurance anXinInsurance = new AnXinInsurance();
        anXinInsurance.packageList = lstAxRequest;

        String xmlString = XmlUtils.convertToXml(anXinInsurance).replace("<anXinInsurance>", "").replace("</anXinInsurance>", "").replace("<axApplyInsuranceRequest>", "").replace("</axApplyInsuranceRequest>", "").replace(" standalone=\"yes\"", "").replace("UTF", "utf");
        String md5Request = null;
        md5Request = DigestUtils.md5Hex("123456" + xmlString);
        String comId = "EC16070003";
        String url = "https://antx11.95303.com/com.isoftstone.iics.bizsupport.epartner/processOrder?" + "sign=" + md5Request + "&comId=" + comId;
        String resposeString = HttpClientUtil.doPostXmlStream(url, xmlString);
        String responseStr = resposeString.replace("<package>", "<ApplyResponsePackage>").replace("</package>", "</ApplyResponsePackage>").replace("<packageList>", "<AXApplyInsuranceResponse>\r\n<packageList>") + "</AXApplyInsuranceResponse>";
//        AXApplyInsuranceResponse axApplyInsuranceResponse = (AXApplyInsuranceResponse)XmlUtils.convertXmlStrToObject(AXApplyInsuranceResponse.class,responseStr);
//        XStream xStream = new XStream(new DomDriver());
//        AXApplyInsuranceResponse axApplyInsuranceResponse = (AXApplyInsuranceResponse) converyToJavaBean(responseStr,AXApplyInsuranceResponse.class);
        ResponseHeader responseHeader = new ResponseHeader();
        XElement root = XElement.loadXml(responseStr);
        responseHeader.requestType = root.element("packageList").element("ApplyResponsePackage").element("header").element("requestType").getValue();
        responseHeader.responseCode = root.element("packageList").element("ApplyResponsePackage").element("header").element("responseCode").getValue();
        responseHeader.errorMessage = root.element("packageList").element("ApplyResponsePackage").element("header").element("errorMessage").getValue();
        responseHeader.sendTime = root.element("packageList").element("ApplyResponsePackage").element("header").element("sendTime").getValue();
        responseHeader.from = root.element("packageList").element("ApplyResponsePackage").element("header").element("from")==null?"":root.element("packageList").element("ApplyResponsePackage").element("header").element("from").getValue();
        responseHeader.orderId = root.element("packageList").element("ApplyResponsePackage").element("header").element("orderId")==null?"":root.element("packageList").element("ApplyResponsePackage").element("header").element("orderId").getValue();
        responseHeader.productCode = root.element("packageList").element("ApplyResponsePackage").element("header").element("productCode")==null?"":root.element("packageList").element("ApplyResponsePackage").element("header").element("productCode").getValue();
        responseHeader.productName = root.element("packageList").element("ApplyResponsePackage").element("header").element("productName")==null?"":root.element("packageList").element("ApplyResponsePackage").element("header").element("productName").getValue();
        List<proposal> lstProposal = new ArrayList<>();
        if (root.element("packageList").element("ApplyResponsePackage").element("response").elements("proposal")!=null)
        {
            for (XElement elmPro: root.element("packageList").element("ApplyResponsePackage").element("response").elements("proposal")) {
                proposal p = new proposal();
                p.ePolicyUrl = elmPro.element("ePolicyUrl").getValue();
                p.insBeginDate = elmPro.element("insBeginDate").getValue();
                p.insEndDate = elmPro.element("insEndDate").getValue();
                p.mainAmount = elmPro.element("totalAmount").getValue();
                p.orderId = elmPro.element("orderId").getValue();
                p.policyNo = elmPro.element("policyNo").getValue();
                p.prodNo = elmPro.element("policyNo").getValue();
                p.totalPremium = elmPro.element("totalPremium").getValue();
                lstProposal.add(p);
            }
        }
        ApplyResponsePackage applyResponsePackage = new ApplyResponsePackage();
        applyResponsePackage.header = responseHeader;
        applyResponsePackage.response = lstProposal;
        return resposeString;
    }



    public String AXCancel() {
        RequestHeader header = new RequestHeader();
        header.requestType = "SURRENDER";
        header.from = "EC16070003";
        header.sendTime = "2022-01-24 12:28:04";
        header.orderId = "JSSJ4089852`6190~16038584{42039a8d-4";
        header.isGroup = "0";
        header.productCode = "TP080113";
        header.productName = "安心延误保障计划（航后款）";

        SurrenderRequest surrenderRequest = new SurrenderRequest();
        Charge charge = new Charge();
        charge.orderId = "JSSJ4089852`6190~16038584{42039a8d-4";
        charge.policyNo = "601000808000221D000000009";

        SurrenderRequestPackage surrenderRequestPackage = new SurrenderRequestPackage();
        surrenderRequestPackage.header = header;
        surrenderRequest.charge = charge;

        surrenderRequestPackage.request = surrenderRequest;

        List<SurrenderRequestPackage> lstSurrenderRequestPackage = new ArrayList<>();
        lstSurrenderRequestPackage.add(surrenderRequestPackage);

        AXSurrenderRequest axSurrenderRequest = new AXSurrenderRequest();
        axSurrenderRequest.packages = lstSurrenderRequestPackage;
        
        AnXinSurrender anXinSurrender = new AnXinSurrender();
        anXinSurrender.packageList = new ArrayList<AXSurrenderRequest>(){
            {
                add(axSurrenderRequest);
            }
        };
        String xmlString = XmlUtils.convertToXml(anXinSurrender).replace("<anXinSurrender>", "").replace("</anXinSurrender>", "").replace(" standalone=\"yes\"", "").replace("UTF", "utf");
        String md5Request = null;
        md5Request = DigestUtils.md5Hex("123456" + xmlString);
        String comId = "EC16070003";
        String url = "https://antx11.95303.com/com.isoftstone.iics.bizsupport.epartner/processOrder?" + "sign=" + md5Request + "&comId=" + comId;
        String resposeString = HttpClientUtil.doPostXmlStream(url, xmlString);
        return resposeString;
    }

    public static <T> T converyToJavaBean(String xml, Class<T> c) {
        T t = null;
        try {
            JAXBContext context = JAXBContext.newInstance(c);
            Unmarshaller unmarshaller = context.createUnmarshaller();
            t = (T) unmarshaller.unmarshal(new StringReader(xml));
        } catch (Exception e) {
            e.printStackTrace();
        }

        return t;
    }
}

